home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7306 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.voicenet.com!news
  2. From: kobak@voicenet.com (Peter Kobak)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: A beginners valiant effort.
  5. Date: 22 Feb 1996 15:55:13 GMT
  6. Organization: Voicenet - Internet Access - (215)674-9290
  7. Message-ID: <4gi3l1$kou@news.voicenet.com>
  8. NNTP-Posting-Host: ivyland243.voicenet.com
  9. X-Newsreader: NeoLogic News for OS/2 [version: 4.2]
  10.  
  11. You didn't leave enough room in string_val_one for the string's terminator. 
  12.  
  13. In message <4g81kr$mrs@soap.news.pipex.net> - chris.neale@ooh.conqueror.co.uk 
  14. (Chris Neale) writes:
  15. :>
  16. :>Please, Please! Help! Why doesn't this work - the book says it should,
  17. :>but the IF statement falls through - like a switch statement. Try it
  18. :>and see.
  19. :>
  20. :>Thanks, Chris
  21. :>
  22. :>please e-mail responses to neales@dial.pipex.com - Ta.
  23. :>
  24. :>
  25. :>#include <iostream.h>
  26. :>#include <string.h>
  27. :>
  28. :>enum boolean{false, true};
  29. :>
  30. :>class switc_string
  31. :>    {
  32. :>    private:
  33. :>        char string_val_one[16];
  34. :>        char string_val_two[12];
  35. :>    public:
  36. :>        void set_string(char string1[], char string2[])
  37. :>        {
  38. :>        strcpy(string_val_one, string1);
  39. :>        strcpy(string_val_two, string2);
  40. :>        }
  41. :>        void get_string(boolean string_index)
  42. :>        {
  43. :>        cout << string_index;
  44. :>        if ( string_index )
  45. :>            {cout << string_val_one;}
  46. :>
  47. :>        else
  48. :>            {cout << string_val_two;}
  49. :>        }
  50. :>    };
  51. :>
  52. :>void main()
  53. :>
  54. :>{
  55. :>
  56. :>switc_string s1;
  57. :>s1.set_string("is not flowering","is flowering");
  58. :>cout << endl;
  59. :>s1.get_string(1);
  60. :>
  61. :>}
  62. :>
  63. :>
  64.  
  65.  
  66.  
  67. ================
  68. Peter Kobak
  69. kobak@voicenet.com
  70.  
  71.  
  72.